<template>
    <div>
        <h1>登录页面</h1>
        <table class="table table-buttoned">
            <tbody>
                <tr>
                    <td>账号</td>
                    <td><input type="text" v-model="info.username" /></td>
                </tr>
                <tr>
                    <td>密码</td>
                    <td><input type="password" v-model="info.userpwd" /></td>
                </tr>
                <tr>
                    <td>密码</td>
                    <td><input type="button" value="登录" class="btn btn-success" @click="login" /></td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import { ref, reactive } from 'vue';
import axios from 'axios';
import { useRouter } from 'vue-router'
//useRouter:作用
const router = useRouter();

let info: any = reactive({
    username: '',
    userpwd: ''
})
const login = () => {
    //验证
    if (info.username == '') {
        alert("账号不能为空");
        return;
    }
    if (info.userpwd == '') {
        alert("密码不能为空")
        return;
    }

    //发送网络请求
    axios({
        url: '/api/Admin/GetAdminModel',//想后端请求的地址
        method: 'get',
        params: info,
    })
        .then(res => {
            console.log(res);
            //请求成功调用 res请求结果
            if (res.data == -1) {
                alert("账号不存在");
                return;
            }
            else if (res.data == -2) {
                alert("密码错误");
                return;
            }
            else {
                alert("登录成功"); //1.提示 或者存储用户信息 跳转
                router.push('/memberLevel');   //创建会员等级路由
            }
        }).
        catch(err => {
            //请求失败  err错误结果
        });
};
</script>

<style scoped></style>